package or;

import org.junit.jupiter.api.Test;

public class T1599 {


    public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {
        int len = customers.length;
        int nowCustomer = 0;
        int profit = 0, tempProfit = 0;
        int times = 0, tempTimes = 0;
        int sum=0;
        int i=0;
        while(i<len || nowCustomer > 0){
            if (i<len)nowCustomer += customers[i];
            if (nowCustomer >= 4) {
                tempProfit=tempProfit+(boardingCost*4-runningCost);
                tempTimes++;
                nowCustomer-=4;
            } else {
                tempProfit += (boardingCost * nowCustomer - runningCost);
                tempTimes++;
                nowCustomer = 0;
            }
            if (tempProfit > 0) {
                profit += tempProfit;
                tempProfit=0;
                times += tempTimes;
                tempTimes=0;
            }else if (i==len){
                break;
            }
            i++;
        }
        if (times == 0) {
            times = -1;
        }
        return times;
    }

    @Test
    public void test() {
        int[] customers = {8,3};
        int re = minOperationsMaxProfit(customers, 5, 6);
        System.out.println(re);

    }

}
